package com.young.springdemo.service.memento;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

//测试备忘录
@Component
public class testMemento {

//    @PostConstruct
    public void testMemento() {
        ChineseChess chineseChess = new ChineseChess("象", 1, 2);
        System.out.println(chineseChess.toString());
        CareTaker careTaker = new CareTaker();
        //save是在下一个保存之前进行save,如果不执行的话,直接就是restore操作
        careTaker.setChineseChessMemento(chineseChess.save());
        chineseChess.setX(2);
        System.out.println(chineseChess.toString());
        careTaker.setChineseChessMemento(chineseChess.save());
        System.out.println(chineseChess.toString());
        chineseChess.setX(3);
        System.out.println(chineseChess.toString());
//        careTaker.setChineseChessMemento(chineseChess.save());
//        System.out.println(chineseChess.toString());
         chineseChess.restore(careTaker.getChineseChessMemento());
        System.out.println(chineseChess.toString());
    }
}
